﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
public partial class PageEdit_Images : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Account"] == null)
        {
            HZ.Common.log4netManager.LogFatal("文件上传", string.Format("IP {0} : 企图上传非法文件", HZ.Fun.GetClientIP()), null);
            HZ.Web.MessageBox.Show("非法上传!!!");
            Response.End();
        }
        if (Page.IsPostBack)
        {
            System.Web.HttpPostedFile _postFile = this.filImgUp.PostedFile;
            if (_postFile.ContentLength > 0)
            {
                string ext = Path.GetExtension(_postFile.FileName);
                ext = ext.ToLower();
                if (ext != ".jpg" && ext != ".gif" && ext != ".jepg" && ext != ".png")
                {
                    HZ.Common.log4netManager.LogError("文件上传类型判断", string.Format("IP {0} : 上传非法类型 {1}", HZ.Fun.GetClientIP(), ext), null);
                    HZ.Web.MessageBox.Show("文件类型非法");
                    return;
                }


                string strFileName = "../UploadFile/" + SysFun.GetIntDate() + "_" + SysFun.GetIntTime() + "_" + SysFun.GetRnd(1000, 9999) + _postFile.FileName.Substring(_postFile.FileName.LastIndexOf("."));
                _postFile.SaveAs(Server.MapPath(strFileName));

                Response.Write("<SCRIPT LANGUAGE=vbscript>\r\n");
                Response.Write("Sub window_onload\r\n");
                Response.Write("window.parent.PasteHtml(\"<img src='" + strFileName + "' border='0'>\")\r\n");
                Response.Write("window.location = \"Images.aspx\"\r\n");
                Response.Write("End Sub\r\n");
                Response.Write("</SCRIPT>\r\n");
                Response.End();
            }
        }
    }
}
